<% content_for :head do %>
  <%= include_javascripts :jquery, :validations %>
<% end %>

<%= form_for [:admin, @user], :validate => true do |f| %>

  <%= render "shared/error_messages", :target => @user %>

  <% f.fields_for :user_info do |user_info| %>
    <table class="form" style="width: 500px;">
      <thead>
        <tr>
          <th colspan="2">Osobní údaje</th>
        </tr>
      </thead>
      <tfoot>
        <tr>
          <th colspan="2"></th>
        </tr>
      </tfoot>
      <tbody>
        <tr>
          <th><%= user_info.label :name %></th>
          <td><%= user_info.text_field :name, :size => 30, :maxlength => 15 %></td>
        </tr>
        <tr>
          <th><%= user_info.label :surname, :required => true %></th>
          <td><%= user_info.text_field :surname, :size => 30, :maxlength => 30 %></td>
        </tr>
        <tr>
          <th><%= user_info.label :hone, :required => true %></th>
          <td><%= user_info.text_field :phone, :maxlength => 16 %></td>
        </tr>
      </tbody>
    </table>

    <table class="form" style="width: 500px;">
      <thead>
        <tr>
          <th colspan="2">Přihlašovací údaje</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th><%= f.label :email %></th>
          <td><%= f.text_field :email, :maxlength => 50, :autocomplete => :off, :size => 30 %></td>
        </tr>
        <% if @user.new_record? %>
          <tr>
            <th>
              <%= form.label :password %>
            </th>
          <td><%= form.password_field :password, :autocomplete => :off, :maxlength => 20, :size => 25 %></td>
          </tr>
          <tr>
            <th>
              <%= form.label :password_confirmation %>
            </th>
            <td><%= form.password_field :password_confirmation, :autocomplete => :off, :maxlength => 20, :size => 25 %></td>
          </tr>
        <% else %>
      </tbody>
        <thead>
          <tr>
            <th colspan="2">Změna hesla</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <th><%= form.label :password, :text => "Nové heslo", :required => true %></th>
            <td><%= form.password_field :password, :autocomplete => :off, :maxlength => 20, :size => 25 %></td>
          </tr>
          <tr>
            <th><%= form.label :password_confirmation, :text => "Potvrzení nového hesla", :required => true %></th>
            <td><%= form.password_field :password_confirmation, :autocomplete => :off, :maxlength => 20, :size => 25 %></td>
          </tr>
        <% end %>
      </tbody>
    </table>

    <% user_info.fields_for :company do |company| %>

    <%= error_messages_for :company %>

    <table class="form" id="company" style="width: 500px;">
        <thead>
          <tr>
            <th colspan="2">Firma (nepovinné)</th>
          </tr>
        </thead>
        <tfoot>
          <tr>
            <th colspan="2"></th>
          </tr>
        </tfoot>
        <tbody>
          <tr>
            <th><%= company.label :name, :required => true %></th> <td><%= company.text_field :name, :maxlength => 30 %></td>
          </tr>
          <tr>
            <th><%= company.label :ico, :required => true %></th> <td><%= company.text_field :ico, :maxlength => 13 %></td>
          </tr>
          <tr>
            <th><%= company.label :dic %></th> <td><%= company.text_field :dic, :maxlength => 13 %></td>
          </tr>
          <tr>
            <th><%= company.label :telephone %></th> <td><%= company.text_field :telephone, :maxlength => 16 %></td>
          </tr>
          <tr>
            <th><%= company.label :function %></th> <td><%= company.text_field :function, :maxlength => 30 %></td>
          </tr>
        </tbody>
      </table>
<% end %>

<% user_info.fields_for :shipping_address do |address| %>

    <%= error_messages_for :shipping_address %>

    <table class="form" style="width: 500px;">
       <thead>
        <tr>
          <th colspan="2">Doručovací adresa</th>
        </tr>
      </thead>
      <tfoot>
        <tr>
          <th colspan="2"></th>
        </tr>
      </tfoot>
      <tbody>
        <tr>
          <th><%= address.label :street, :required => true %></th> <td><%= address.text_field :street, :maxlength => 40 %></td>
        </tr>
        <tr>
          <th><%= address.label :city, :required => true %></th> <td><%= address.text_field :city, :maxlength => 30 %></td>
        </tr>
        <tr>
          <th><%= address.label :zip, :required => true %></th> <td><%= address.text_field :zip, :maxlength => 6 %></td>
        </tr>
      </tbody>
    </table>
    <%= address.hidden_field :address_type, :value => "shipping" %>
<% end %>

<p>
  <%= user_info.label :use_billing_address %>
  <%= user_info.check_box :use_billing_address, :onchange => "document.getElementById('billing_address').style.display = (this.checked ? 'none' : 'block');" %>
</p>
  <% user_info.fields_for :billing_address do |address| %>

    <%= error_messages_for :billing_address %>

    <div id="billing_address" style="<% if @user.user_info.use_billing_address == '1' %>display:none;<% end%>">
    <table class="form" style="width: 500px;">
       <thead>
        <tr>
          <th colspan="2">Fakturační adresa</th>
        </tr>
      </thead>
      <tfoot>
        <tr>
          <th colspan="2"></th>
        </tr>
      </tfoot>
      <tbody>
        <tr>
          <th><%= address.label :street, :required => true %></th> <td><%= address.text_field :street, :maxlength => 40 %></td>
        </tr>
        <tr>
          <th><%= address.label :city, :required => true %></th> <td><%= address.text_field :city, :maxlength => 30 %></td>
        </tr>
        <tr>
          <th><%= address.label :zip, :required => true %></th> <td><%= address.text_field :zip, :maxlength => 6 %></td>
        </tr>
      </tbody>
    </table>
    </div>
    <%= address.hidden_field :address_type, :value => "billing" %>
  <% end %>
<% end %>